package nccloud.web.hihr.ext.action;

import java.util.ArrayList;
import java.util.List;

import nc.bs.framework.json.core.exception.ExceptionUtils;
import nc.itf.hrhi.bill.IXcHrExtBillService;
import nc.vo.pub.BusinessException;
import nccloud.framework.service.ServiceLocator;
import nccloud.framework.web.container.IRequest;
import nccloud.framework.web.container.SessionContext;
import nccloud.pubitf.platform.attachment.WebFileParaVO;
import nccloud.web.platform.attachment.action.AttachmentQueryAction;

public class XcAttachmentQueryAction extends AttachmentQueryAction{

	@Override
	public Object doAction(IRequest request) {
		
		List<String> fileTypeList = null;
		try {
			fileTypeList = ServiceLocator.find(IXcHrExtBillService.class).queryFileTypeByUserPower(SessionContext.getInstance().getClientInfo().getUserid());
			
			if(fileTypeList == null || fileTypeList.size() == 0) {
				return null;
			}
			
		} catch (BusinessException e) {
			ExceptionUtils.wrapException(e);
		}
		
		WebFileParaVO[] ret = (WebFileParaVO[]) super.doAction(request);
		
		List<WebFileParaVO> list = new ArrayList<WebFileParaVO>();
		
		if(ret != null && ret.length > 0) {
			String fullpath = null;
			String filetype = null;
			for(WebFileParaVO vo : ret) {
				fullpath = vo.getFullPath();
				fullpath = fullpath.substring(21, fullpath.length());
				filetype = fullpath.split("/")[0];
				
				if(fileTypeList.contains(filetype)) {
					list.add(vo);
				}
			}
			
			if(list.size() > 0) {
				WebFileParaVO[] newrt = new WebFileParaVO[list.size()];
				list.toArray(newrt);
				return newrt;
			}else {
				return new WebFileParaVO[0];
			}
			
		}
		
		return ret;
	}
}
